#!/usr/bin/env node

var tidy = require('./').tidy,
    argv = require('minimist')(process.argv.slice(2)),
    fs = require('fs');

var filename = argv._[0] || '';

if (!filename) {
    return help();
}

// Output

output = tidy(JSON.parse(fs.readFileSync(filename, 'utf8')), {"minimumDistance": argv.d, "minimumTime": argv.t, "maximumPoints": argv.m});

console.log(JSON.stringify(output));

// Help
function help() {
    console.error('Usage: geojson-tidy [-d minimum distance between points] [-t minimum sample time between points] [-m maximum number of points in a single line feature] FILE\n' +
        'FILE is any valid geojson file generated by togeojson\n' +
        'geojson-tidy returns a stingified gejosn FeatureCollection\n' +
        'Example: ./geojson-tidy test/walk-1.json -d 10 -t 5 -m 100 > output.json');
}